package 双指针;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class 两数之和 {
    public int[] twoSum(int[] nums, int target) {
        int[] ints = new int[2];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target-nums[i])){
                ints[0]=i;
                ints[1]=map.get(target-nums[i]);
        }
            else
                map.put(nums[i],i);
    }
        return ints;
    }
}
